package com.vimi8.ebb.sqlprovider;


import com.vimi8.ebb.model.ElectricityBusiness;
import com.vimi8.ebb.model.ProductInfo;
import com.vimi8.ebb.model.TrainInfo;
import com.vimi8.ebb.model.TrainMember;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
 * Created by think on 2016/7/7.
 */
public class TrainInfoSqlProvider {
    private Logger logger =  LoggerFactory.getLogger(this.getClass());

    //getInsertTrainInfoSql

    public String getInsertTrainMemberSql(Map<String, Object> parameters){
        StringBuilder sqlSb=new StringBuilder();
        List<TrainMember> trainMemberList=  ( List<TrainMember>)parameters.get("trainMemberList");
        sqlSb.append("insert into train_members(id,train_id,member_name,member_type,member_sex,member_phone,enter_orientation,train_evaluate,member_address) VALUES");
        int count=0;
        for(TrainMember trainMember:trainMemberList){
            sqlSb.append("('");
            sqlSb.append(trainMember.getId()+"','");
            sqlSb.append(trainMember.getMemberName()+"','");
            sqlSb.append(trainMember.getMemberType()+"','");
            sqlSb.append(trainMember.getMemberSex()+"','");
            sqlSb.append(trainMember.getMemberPhone()+"','");
            sqlSb.append(trainMember.getEnterOrientation()+"','");
            sqlSb.append(trainMember.getTrainEvaluate()+"','");
            sqlSb.append(trainMember.getMemberAddress()+"'");

            if(trainMemberList.size()-1>count){
                sqlSb.append("),");
            }else{
                sqlSb.append(");");
            }

            count++;
        }
        logger.info("sqlStr="+sqlSb.toString());
        return sqlSb.toString();
    }
    //getInsertTrainMemberSql

    public String getInsertTrainInfoSql(Map<String, Object> parameters){
        StringBuilder sqlSb=new StringBuilder();
        List<TrainInfo> trainInfoList=  ( List<TrainInfo>)parameters.get("trainInfoList");
        sqlSb.append("insert into train_info(id,train_address,train_address_code,train_teacher,sex,phone,train_object,train_date,train_title,train_content,train_type,train_evaluate,train_peoples) VALUES");
        int count=0;
        for(TrainInfo trainInfo:trainInfoList){
            sqlSb.append("('");
            sqlSb.append(trainInfo.getId()+"','");
            sqlSb.append(trainInfo.getTrainAddress()+"','");
            sqlSb.append(trainInfo.getTrainAddressCode()+"','");
            sqlSb.append(trainInfo.getTrainTeacher()+"','");
            sqlSb.append(trainInfo.getSex()+"','");
            sqlSb.append(trainInfo.getPhone()+"','");
            sqlSb.append(trainInfo.getTrainObject()+"','");
            sqlSb.append(trainInfo.getTrainDate()+"','");
            sqlSb.append(trainInfo.getTrainTitle()+"','");
            sqlSb.append(trainInfo.getTrainContent()+"','");
            sqlSb.append(trainInfo.getTrainType()+"','");
            sqlSb.append(trainInfo.getTrainEvaluate()+"','");
            sqlSb.append(trainInfo.getTrainPeoples()+"'");
            if(trainInfoList.size()-1>count){
                sqlSb.append("),");
            }else{
                sqlSb.append(");");
            }

            count++;
        }
        logger.info("sqlStr="+sqlSb.toString());
        return sqlSb.toString();
    }
}
